package com.example.demo.service;

import com.example.demo.entity.CultureBackgroundDetail;
import com.example.demo.entity.Instrument;
import com.example.demo.mapper.CultureBackgroundDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CultureBackGroundDetailImpl implements CultureBackgroundDetailService {

    @Autowired
    private CultureBackgroundDetailMapper mapper;

    @Override
    public List<CultureBackgroundDetail> getAllDetails() {
        return mapper.findAll();
    }

    @Override
    public List<CultureBackgroundDetail> searchByTitle(String title) {
        return mapper.findByTitle(title);
    }

    @Override
    public void addDetail(CultureBackgroundDetail detail) {
        mapper.insert(detail);
    }

    @Override
    public void updateDetail(CultureBackgroundDetail detail) {
        mapper.update(detail);
    }

    @Override
    public void deleteDetail(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public List<CultureBackgroundDetail> getHotBackground() {
        return mapper.findHotBackground();
    }

    @Override
    public CultureBackgroundDetail getDetailById(Integer id) {
        CultureBackgroundDetail detail = mapper.findById(id);
        if (detail == null) {
            throw new RuntimeException("CultureBackgroundDetail not found with ID: " + id);
        }
        return detail;
    }

    @Override
    public void incrementViewCount(Integer id) {
        mapper.incrementViewCount(id);
    }
}
